package gupiao.cn.lhl.dao.impl;

import gupiao.cn.lhl.dao.IAccountDao;
import gupiao.cn.lhl.entity.Account;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2017/4/2/002.
 */

@Repository
public class AccountDaoImpl implements IAccountDao {
    @Resource
    JdbcTemplate jdbcTemplate;

    public int addAccount(Account account) {
        String sql="insert into account(aname,amaney) values(?,?)";
        return jdbcTemplate.update(sql,account.getAname(),account.getAmaney());
    }

    public int updateAccount(double maney, int aid, boolean is) {
        String sql="";
        if(is){
            sql="update account set amaney=amaney+? where aid=?";
        }else{
            sql="update account set amaney=amaney-? where aid=?";
        }
        return jdbcTemplate.update(sql,maney,aid);
    }
}
